package com.sinosoft.vaccinetoai.server.business.chatchainrecord.addchatchainrecord.service.impl;

import com.sinosoft.vaccinetoai.dao.mapper.business.ChatChainRecordMapper;
import com.sinosoft.vaccinetoai.dao.po.business.ChatChainRecord;
import com.sinosoft.vaccinetoai.server.business.chatchainrecord.addchatchainrecord.io.AddChatChainRecordListIO;
import com.sinosoft.vaccinetoai.server.business.chatchainrecord.converter.ChatChainRecordConverter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import com.sinosoft.vaccinetoai.server.business.chatchainrecord.addchatchainrecord.vo.AddChatChainRecordVO;
import com.sinosoft.vaccinetoai.server.business.chatchainrecord.addchatchainrecord.service.IAddChatChainRecordService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: AddChatChainRecordServiceImpl
 * @ClassNameExplain: 
 * @Description: 新增聊天链历史列表Service Impl
 * @author xiazhihao
 * @date 2023年12月18日 22:31
 */
@Slf4j
@Service("AddChatChainRecordService")
public class AddChatChainRecordServiceImpl implements IAddChatChainRecordService {

	@Resource
	ChatChainRecordMapper chatChainRecordMapper;

	@Override
	public AddChatChainRecordVO addChatChainRecord(AddChatChainRecordListIO io) throws Exception {
        AddChatChainRecordVO vo = new AddChatChainRecordVO();
		List<ChatChainRecord> chatChainRecords = ChatChainRecordConverter.toChatChainRecords(io.getAddChatChainRecordIOS());
		chatChainRecordMapper.batchSave(chatChainRecords);
		//组装出新增消息的id 用于后续具体聊天记录上链
		List<Long> chatChaiIds = chatChainRecords.stream().map(ChatChainRecord::getId).collect(Collectors.toList());
		vo.setChatChaiIds(chatChaiIds);
		return vo;
	}
	
}